package com.base.thread;

/**
 * @author innocent
 * @date 2019/1/23 11:53
 */
public class JoinTest {

    public static void main(String[] args) {
        FatherThread fatherThread = new FatherThread();
        Thread thread = new Thread(fatherThread);
        thread.start();
    }

}

class FatherThread implements Runnable{

    @Override
    public void run() {
        System.out.println("-------爸爸想抽烟------");
        System.out.println("-------爸爸让儿子去买烟------");
        SonThread sonThread = new SonThread();
        Thread son = new Thread(sonThread);
        son.start();
        try {
            son.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
            System.out.println("爸爸出去找儿子");
        }
        System.out.println("-------爸爸高兴地抽着香烟，给了儿子零花钱------");

    }
}

class SonThread implements Runnable{

    @Override
    public void run() {
        System.out.println("----------儿子去买香烟-------");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("----------儿子买完香烟回来---------");
    }
}
